//package com.plian.system.controller.pm.investmentupnotice;
//
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.*;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.entity.pm.investmentupnotice.InvestmentupNotice;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.R;
//import com.plian.system.model.token.PassToken;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.pm.investmentupnotice.IInvestmentupNoticeService;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.pm.investmentupnotice.InvestmentupNoticeVO;
//import com.plian.system.wrapper.pm.investmentupnotice.InvestmentupNoticeWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
///**
// *
// *
// */
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/investmentupnotice")
//public class InvestmentupNoticeController extends BaseController {
//
//	private IInvestmentupNoticeService investmentupNoticeService;
//	private FileService fileService;
//	private FormWorkflowService formWorkflowService;
//
//	private InvestmentupNoticeWrapper investmentupNoticeWrapper;
//
//	/**
//	 * 详情
//	 */
//	@PostMapping("/detail")
//	public R<InvestmentupNoticeVO> detail(@Valid @RequestBody InvestmentupNotice investmentupNotice) {
//		InvestmentupNoticeVO investmentupNoticeVO = investmentupNoticeWrapper.entityToVO(investmentupNoticeService.getOne(Condition.getQueryWrapper(investmentupNotice)));
//		return investmentupNoticeService.getDetailObj(investmentupNoticeVO);
//	}
//
//	/**
//	 * 分页
//	 */
//	@PostMapping("/list")
//	public ListResult<InvestmentupNoticeVO> list(@Valid @RequestBody Query query) {
//		if (query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//
//		List<SearchEntity> entityList = query.getSearch();
//		QueryWrapper<InvestmentupNotice> queryWrapper = SearchParamEntiy.getQueryWrapper(
//				Condition.getQueryWrapper(new InvestmentupNotice()), entityList
//		);
//		queryWrapper.eq("create_company_id", TokenUtil.getTokenOrgId());
//		IPage<InvestmentupNotice> pages = investmentupNoticeService.page(Condition.getPage(query), queryWrapper);
//
//		List<InvestmentupNoticeVO> investmentupNoticeVOS = investmentupNoticeWrapper.entityToVO(pages.getRecords());
//		ListResult<InvestmentupNoticeVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(investmentupNoticeVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//	/**
//	 * 新增或修改
//	 */
//	@PostMapping("/submit")
//	public R submit(@Valid @RequestBody InvestmentupNoticeVO investmentupNoticeVO) {
//		Boolean checkResult = false;
//
//		if (!(Optional.ofNullable(investmentupNoticeVO.getStatus()).isPresent() && investmentupNoticeVO.getStatus() == FormStatusConstant.STASH)){
//			checkResult = investmentupNoticeService.checkIsExisted(investmentupNoticeVO.getId(),investmentupNoticeVO.getCode());
//		}
//
//		if(checkResult){
//			if (StringUtil.isBlank(investmentupNoticeVO.getVersion())){
//				investmentupNoticeVO.setVersion("1");
//			}
//
//			if (Optional.ofNullable(investmentupNoticeVO.getStatus()).isPresent() && investmentupNoticeVO.getStatus() != FormStatusConstant.STASH){
//				investmentupNoticeVO.setFormType(String.valueOf(FormTypeConstant.CQZC_INVESTMENTUP_NOTICE));
//			}
//			InvestmentupNotice investmentupNotice = new InvestmentupNotice();
//			BeanUtils.copyProperties(investmentupNoticeVO, investmentupNotice);
//			boolean result = investmentupNoticeService.saveOrUpdate(investmentupNotice);
//			if(result) {
//				investmentupNoticeVO.setId(investmentupNotice.getId());
//				investmentupNoticeService.saveChild(investmentupNoticeVO);
//				List<HashMap> listDoc = investmentupNoticeVO.getList_doc();
//				fileService.edit(investmentupNotice.getId().toString(),listDoc);
//			}
//
//			HashMap<String, Object> processVariable = new HashMap<>();
//			formWorkflowService.startProcessAndSimulate(String.valueOf(investmentupNoticeVO.getId()),investmentupNoticeVO.getFormType(),processVariable);
//
//			return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//		}else {
//			return new R(CommonCode.FAIL);
//		}
//	}
//
//	/**
//	 * 删除
//	 */
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//		List<String> ids = (List<String>)pd.get("ids");
//		return investmentupNoticeService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA))) ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	 * 打印
//	 */
//	@GetMapping("/buildpdf/{id}")
//	@PassToken
//	public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) throws Exception {
//		return FileTools.exportPdf(investmentupNoticeService.createReceptFile(id));
//	}
//
//	/**
//	 * 分页
//	 */
//	@PostMapping("/reportList")
//	public ListResult<PageData> reportList( @RequestBody PageData pd) {
//		return investmentupNoticeService.reportList(pd);
//	}
//}
